import 'package:flutter/material.dart';
import '../appConfig.dart' show AppColor, AppFamily;
import '../pages/home_main_pages.dart';

enum Actions {
  ADD_GROUPCHAT,
  ADD_FRIEND,
  ADD_SEE,
  ADD_PAYMENT
}

class HomeScreen extends StatefulWidget {
  HomeScreen({Key key}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
   var _currentIndex = 0;

  _popItemWidget(int iconName, String string) {
    return Row(
      children: <Widget>[
        Icon(
          IconData(
          iconName,
          fontFamily: AppFamily.IconFontFamily,
          ),
          color: Colors.white,
        ),
        Container(width: 12.0,),
        Text(string,
          style: TextStyle(color: Colors.white),
        )
      ],
    );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        title: Text('微信', style: TextStyle(color: Color(0xff383838)),),
        actions: <Widget>[
          PopupMenuButton(
            padding: const EdgeInsets.all(10.0),
            itemBuilder:(BuildContext context) =>  <PopupMenuEntry<Actions>>[
              PopupMenuItem(
                child: _popItemWidget(0xe602, '发起群聊'),
                value: Actions.ADD_GROUPCHAT,
              ),
              PopupMenuItem(
                child: _popItemWidget(0xe602, '添加朋友'),
                value: Actions.ADD_FRIEND,
              ),
              PopupMenuItem(
                child: _popItemWidget(0xe602, '扫一扫'),
                value: Actions.ADD_SEE,
              ),
              PopupMenuItem(
                child: _popItemWidget(0xe602, '收付款'),
                value: Actions.ADD_PAYMENT,
              ),
              
            ],
            onSelected: (Actions action) {
              print(action);
            },
            icon: Icon(Icons.add_circle, color: Color(AppColor.TabbarTextColors)),
            color: Color(AppColor.TabbarIconColorNormal),
          ),

        ],
      ),
      body: HomePages(),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              IconData(
                0xe602,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorNormal),
            ),
            activeIcon: Icon(
              IconData(
                0xe603,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorSelected),
            ),
            title: Text('微信', 
            style: TextStyle(
              color: _currentIndex == 0 ? Color(AppColor.TabbarIconColorSelected) : Color(AppColor.TabbarTextColors),
              fontSize: 14
            )
            )
          ),
          BottomNavigationBarItem(
            icon: Icon(
              IconData(
                0xe600,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorNormal),
            ),
            activeIcon: Icon(
              IconData(
                0xe601,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorSelected),
            ),
            title: Text('通讯录',
            style: TextStyle(
              color: _currentIndex == 1 ? Color(AppColor.TabbarIconColorSelected) : Color(AppColor.TabbarTextColors),
              fontSize: 14
            )
            )
          ),
          BottomNavigationBarItem(
            icon: Icon(
              IconData(
                0xe617,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorNormal),
            ),
            activeIcon: Icon(
              IconData(
                0xe609,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorSelected),
            ),
            title: Text('发现',
            style: TextStyle(
              color: _currentIndex == 2 ? Color(AppColor.TabbarIconColorSelected) : Color(AppColor.TabbarTextColors),
              fontSize: 14
            )
            )
          ),
          BottomNavigationBarItem(
            icon: Icon(
              IconData(
                0xe605,
                fontFamily: AppFamily.IconFontFamily
              ),
              color: Color(AppColor.TabbarIconColorNormal),
            ),
            activeIcon: Icon(
              IconData(
                0xe604,
                fontFamily: AppFamily.IconFontFamily,
              ),
              color: Color(AppColor.TabbarIconColorSelected),
            ),
            title: Text('我的',
            style: TextStyle(
              color: _currentIndex == 3 ? Color(AppColor.TabbarIconColorSelected) : Color(AppColor.TabbarTextColors),
              fontSize: 14
            )
            )
          ),
        ],
        backgroundColor: Color(0xffF7F7F7),
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}